home *** CD-ROM | disk | FTP | other *** search
/ PC-Blue - MS DOS Public Domain Library / PC-Blue MS-DOS Public Domain Library - NYACC.iso / vol030 / growth.bas < prev    next >
Encoding:
BASIC Source File  |  1987-01-11  |  6.4 KB  |  142 lines

  1. 10 KEY OFF
  2. 30 WIDTH 80:SCREEN 0:COLOR 7,0:CLS
  3. 40 DIM F(53)
  4. 49 COLOR 0,7:PRINT SPC(79):LOCATE 1,1
  5. 50 PRINT TAB(5);"Growth Rate        and       Projections  via  Exponential Regression":COLOR 7,0
  6. 60 PRINT
  7. 70 PRINT
  8. 81 PRINT "    This program analyzes the trend (of some value) for past periods,"
  9. 82 PRINT "    computes an average growth rate, and projects future figures."
  10. 83 PRINT :PRINT "    If entering new data ---":PRINT "    You will be asked to specify the number of past periods, and then the number    of future periods to project.  ";
  11. 84 PRINT "For each of the past periods, you must then":PRINT "    enter the number of items. (the number must be non-zero)"
  12. 85 PRINT :PRINT "    The total number of periods (past + future) cannot exceed 52."
  13. 90 PRINT
  14. 100 PRINT
  15. 150 LINE INPUT;"Do you want to enter new <new> or review old <old> data ? ";TODO$:TODO$=LEFT$(TODO$,1)
  16. 160 IF TODO$="n" OR TODO$="N" THEN PRINT :GOTO 200
  17. 165 IF TODO$<>"o" AND TODO$<>"O" THEN PRINT:GOTO 150
  18. 170 PRINT :LINE INPUT"What is the file name of the old data you want to review ?";OLD$:OLD$=LEFT$(OLD$,12):LOCATE 25,10:PRINT "Please stand by while the file is read in";:IF OLD$="" THEN RUN
  19. 175 OPEN OLD$ FOR INPUT AS #1 : J=0
  20. 176 INPUT#1, TITLE$:INPUT #1, M,P
  21. 177 WHILE NOT EOF(1) : J=J+1:IF J>52 THEN 188 ELSE INPUT#1,F(J):WEND
  22. 188 GOTO 300
  23. 199 REM .. data entry
  24. 200 PRINT :LINE INPUT "How many past periods: ? ";M$:M=VAL(M$)
  25. 210 LINE INPUT "How many periods to project (future): ? ";P$:P=VAL(P$):IF P<0 THEN P=0
  26. 220 IF M+P>52 THEN PRINT :PRINT "ONLY 52 PERIODS PLEASE  !":GOTO 100
  27. 225 IF M=<0 THEN PRINT :PRINT "Number of past periods can't = ";M;"!":GOTO 100
  28. 230 PRINT
  29. 240 PRINT "Now enter amounts for past periods :"
  30. 250 PRINT
  31. 260 FOR J=1 TO M
  32. 270 PRINT "Period ";J;": ? ";
  33. 280 LINE INPUT;F$:F(J)=VAL(F$):IF F(J) > 0!  THEN 290
  34. 282 Y=CSRLIN:SOUND 40,20:LOCATE 25,1:PRINT "Sorry, you must enter a numeric value > 0";:LOCATE Y,1:PRINT SPC(30);:LOCATE Y,1:GOTO 270
  35. 290 PRINT :NEXT J
  36. 299 REM .. perform exponential regression
  37. 300 T=LOG(F(1)):TOTAL=0
  38. 310 V=0
  39. 320 FOR J=2 TO M
  40. 325 IF J>52 THEN J=52 GOTO 360
  41. 330 L=LOG(F(J))
  42. 340 T=T+L
  43. 350 V=V+(J-1)*L
  44. 360 NEXT J
  45. 370 A=6*(2*V/(M-1)-T)/M/(M+1)
  46. 380 A=EXP(A)-1
  47. 390 AGF=EXP(T/M-A*(M-1)/2)
  48. 399 REM .. project values for future periods
  49. 400 FOR J=M+1 TO M+P
  50. 410 F(J)=INT(AGF*(1+A)^(J-1)+.5)
  51. 420 NEXT J
  52. 430 MIN=F(1)
  53. 440 MAX=F(1)
  54. 450 FOR J=1 TO M+P
  55. 455 IF J<=M THEN TOTAL=TOTAL+F(J)
  56. 460 IF F(J)>MAX THEN MAX=F(J)
  57. 470 IF F(J)<MIN THEN MIN=F(J)
  58. 480 NEXT J
  59. 490 S=168/(MAX+MIN) : AVG=TOTAL/M  'find graph scale factor (s), 168 is number                                      of vertical dots space left
  60. 999 REM .. results in tabular form
  61. 1000 CLS:Y=1:X=1:ROW14=0:Y1=1
  62. 1010 FOR J=1 TO M
  63. 1030 LOCATE Y,X
  64. 1040 PRINT "Period #";J;F(J);
  65. 1042 Y=Y+1
  66. 1043 IF Y=14 THEN Y=1:X=X+20:ROW14=-1
  67. 1050 NEXT J
  68. 1051 IF ROW14 THEN Y=14:X=1 ELSE X=1
  69. 1052 LOCATE Y,X:FOR J1=1 TO 79 : PRINT CHR$(240);:NEXT:LOCATE Y,33:PRINT " PROJECTED ":Y=Y+1:Y1=Y
  70. 1053 FOR J=M+1 TO M+P : IF X>79 THEN X=1
  71. 1054 LOCATE Y,X
  72. 1055 PRINT "Period #";J;" ";F(J);:Y=Y+1
  73. 1056 IF Y=23 THEN Y=Y1:X=X+20
  74. 1058 NEXT J
  75. 1060 LOCATE 23,1:PRINT "** (Growth Rate =";INT(A*10000+.5)/100;"%";
  76. 1065 PRINT "   Average value for the past ";M;" periods = ";AVG;")";
  77. 1066 LOCATE 24,5:PRINT TITLE$;
  78. 1070 LOCATE 25,1:LINE INPUT;"Press  Return  to continue ... ";GOON$
  79. 1099 REM .. plot individual data points < scatter graph >
  80. 1100 GOSUB 2010
  81. 1110 FOR J=1 TO M+P
  82. 1120 IF J>M THEN C=1
  83. 1130 PSET (J*11+45,200-INT(S*F(J))),C
  84. 1140 NEXT J
  85. 1199 REM .. plot line graph
  86. 1200 GOSUB 2000
  87. 1202 FLAG!=0  'false
  88. 1205 IF ASC(A$)=27 THEN SCREEN 0 : GOTO 1000
  89. 1207 IF FLAG! THEN GOSUB 2010
  90. 1210 PSET (56,200-INT(S*F(1))),C
  91. 1220 FOR J=2 TO M+P
  92. 1230 IF J>M THEN C=1
  93. 1240 LINE -(J*11+45,200-INT(S*F(J))),C
  94. 1250 NEXT J
  95. 1260 REM .. plot individual data points, connect them with a line <line graph>
  96. 1262 GOSUB 2000
  97. 1264 FLAG!=0  'false
  98. 1266 IF ASC(A$)=27 THEN 1100
  99. 1268 IF FLAG! THEN GOSUB 2010
  100. 1269 IF M+P<24 THEN R1=2 ELSE R1=3   'used to set radius of circle on linegraph
  101. 1270 PSET (56,200-INT(S*F(1))),C  : CIRCLE (56,200-INT(S*F(1))),R1,1,,6.2831
  102. 1272 FOR J=2 TO M+P
  103. 1274 IF J>M THEN C=1
  104. 1276 P1=J*11+45 : P2=200-INT(S*F(J))
  105. 1278 LINE -(P1,P2),C : CIRCLE (P1,P2),R1,1,,6.2831  : PAINT (P1,P2),2,1
  106. 1280 NEXT J
  107. 1299 REM .. plot a bar graph
  108. 1300 GOSUB 2000
  109. 1303 IF ASC(A$)=27 THEN FLAG!=-1 : GOTO 1207
  110. 1310 FOR J=1 TO M+P
  111. 1320 IF J>M THEN C=1
  112. 1330 LINE (J*11+45,200)-(J*11+54,200-INT(S*F(J))),C,BF
  113. 1340 NEXT J
  114. 1399 REM .. store this data if requested
  115. 1400 A$=INPUT$(1) : IF ASC(A$)=27 THEN FLAG!=-1 : GOTO 1268
  116. 1402 SCREEN 0:WIDTH 80:CLS:LOCATE 3,1
  117. 1404 LINE INPUT;"Do you wish to review this data again ? ";YORN$:YORN1$=LEFT$(YORN$,1):IF YORN1$="y" OR YORN1$="Y" THEN 1000
  118. 1408 LOCATE 6,1:LINE INPUT;"Do you want to save this data  ? ";YORN$:YORN1$=LEFT$(YORN$,1):IF YORN1$<>"y" AND YORN1$<>"Y" AND YORN1$<>"n" AND YORN1$<>"N" THEN 1402
  119. 1409 IF YORN1$="n" OR YORN1$="N" THEN 1510
  120. 1410 LOCATE 8,1:LINE INPUT;"Please enter the file name (8 characters max) : ? ";FILENAME$:FILENAME$=LEFT$(FILENAME$,8):FILENAME$=FILENAME$+".gro"
  121. 1412 LOCATE 10,1:LINE INPUT;"Please specify a title for this data ? ";TITLE$
  122. 1420 OPEN FILENAME$ FOR OUTPUT AS #1:PRINT #1,LEFT$(TITLE$,70):PRINT #1, M;P
  123. 1430 FOR J=1 TO M+P : PRINT#1, F(J) : NEXT
  124. 1440 CLOSE#1
  125. 1510 SCREEN 0,0,0
  126. 1520 RUN
  127. 1999 REM .. select graphic screen resolution, choose colors (c), display titles             & scaled values.  Then return to perform the graph
  128. 2000 A$=INPUT$(1) : IF A$="" THEN A$="."  'dummy
  129. 2002 IF ASC(A$)=27 THEN RETURN
  130. 2010 CLS
  131. 2020 SCREEN 2,0 : IF M+P < 24 THEN SCREEN 1,0
  132. 2030 IF M+P < 24 THEN COLOR 0,7
  133. 2040 IF M+P < 24 THEN C=2 ELSE C=1
  134. 2050 PRINT "Average Growth Rate = ";INT(A*10000+.5)/100;"%";
  135. 2070 IF M+P<24 THEN PRINT :PRINT "Amount";:PRINT " ||    <----------- Periods ---------->": PRINT " \/    1  3   6   9   12  15  18  21  24";:GOTO 2088
  136. 2080 PRINT "   Average value for past";M;"periods =";AVG:PRINT "Amount  ";TITLE$:PRINT " ||    <------------------------------- Periods ------------------------------>"
  137. 2085 PRINT " \/    1  3   6   9   12  15  18  21 23  26  29  32 34 36 38  41  44  47  50  53";
  138. 2088 IF M+P<24 THEN 2200
  139. 2100 FOR J=5 TO 25 STEP 2:LOCATE J,1:PRINT INT((168-(J/5-1)*40)/S+.5);:NEXT:RETURN
  140. 2200 FOR J=5 TO 25 STEP 3:LOCATE J,1:PRINT INT((168-(J/5-1)*40)/S+.5);:NEXT:RETURN
  141. T INT((168-(J/5-1)*40)/S+.5);:NEXT:RETURN
  142. 2200 FOR J=5 TO 25 STEP 3:LOCATE J,1:PRINT